package com.zhuanzhuan.hero.user.exception;

import com.zhuanzhuan.hero.user.enums.ExceptionMsgEnum;
import lombok.Getter;

/**
 * @ClassName BusinessException
 * @Description
 * @Author hanjunjun
 * @Date 2024/6/17 21:06
 */
@Getter
public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = -5536124379496272412L;

    private final Integer code;

    private final String message;

    public BusinessException(String message) {
        super(message);
        this.code = -1;
        this.message = message;
    }

    public BusinessException(String message, Throwable throwable) {
        super(message);
        super.initCause(throwable);
        this.code = -1;
        this.message = message;
    }

    public BusinessException(ExceptionMsgEnum exceptionMsgEnum) {
        super(exceptionMsgEnum.getErrorMsg());
        this.code = exceptionMsgEnum.getCode();
        this.message = exceptionMsgEnum.getErrorMsg();
    }

    public BusinessException(ExceptionMsgEnum exceptionMsgEnum, Throwable throwable) {
        super(exceptionMsgEnum.getErrorMsg());
        super.initCause(throwable);
        this.code = exceptionMsgEnum.getCode();
        this.message = exceptionMsgEnum.getErrorMsg();
    }

    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }
}
